package net.zjitc.mapper;

import net.zjitc.po.Orders;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

/**
 * Created by Administrator on 2018/1/3.
 */

public interface OrdersAnnotationMapper {

    //通过id查询订单 查询此订单下的所有订单详情

    /*
    * */
    @Select("select * from orders where id = #{id}")
    @Results({
           @Result(id = true,column = "id",property = "id") ,
            @Result(column = "user_id",property = "user_id"),
            @Result(column = "number",property = "number"),
            @Result(column = "createtime",property = "createtime"),
            @Result(column = "note",property = "note"),
            /*
             property:user表示实体类对应的列名
            * one:表示一对一的关系
            * select：通过user_id查询用户信息
            * */
            @Result(property = "user",column = "user_id",
            one = @One(
                    select = "net.zjitc.mapper.UserAnnotationMapper.findById",
                    fetchType = FetchType.LAZY
            )
            ),
            /*查询一对多的关联关系*/
            @Result(property = "ordersItemList" ,column = "id",
            many = @Many(
                    select = "",
                    fetchType = FetchType.LAZY
            ))
    })
    Orders findByOrdersId(int id);

}
